export const getLevelOption = () => {
  return {
    color: color,
    title: {
      text: "等级比例",
      top: 20,
      left: "center",
      textStyle: {
        fontSize: 20,
        color: "#fff",
      },
    },
    legend: {
      orient: "horizontal",
      bottom: 10,
      textStyle: {
        color: "#fff",
        padding: [0, 0, 0, -35],
        fontSize: 10,
      },
      itemWidth: 33,
      itemHeight: 22,
    },
    series: [
      {
        name: "",
        type: "pie",
        radius: ["50%", "52%"],
        hoverAnimation: true,
        data: setChartOption(data),
      },
    ],
  };
};
const color = [
  "#0CD2E6",
  "#3751E6",
  "#FFC722",
  "#886EFF",
  "#008DEC",
  "#114C90",
  "#00BFA5",
];
const data = [
  {
    name: "A类型",
    value: 20,
  },
  {
    name: "B类型",
    value: 10,
  },
  {
    name: "C类型",
    value: 15,
  },
  {
    name: "D类型",
    value: 23,
  },
  {
    name: "E类型",
    value: 10,
  },
  {
    name: "F类型",
    value: 12,
  },
];
// 设置数据
function setChartOption(data: any) {
  const formatData = [] as any[];
  data.forEach(
    function (item: any, index: any) {
      formatData.push({
        label: {
          color: color[index],
          formatter(param: any) {
            return (
              param.name +
              " (" +
              ((param.percent / 100) * 100).toFixed(2) +
              "%)"
            );
          },
        },
        value: item.value,
        name: item.name,
        itemStyle: {
          color: "#1890ff",
          borderWidth: 13,
          shadowBlur: 20,
          borderRadius: 10,
          borderColor: color[index],
          shadowColor: color[index],
        },
      });
    },
  );

  return formatData;
}
